//
//  ThemeLabel.m
//  WXWeibo
//
//  Created by apple on 16/5/10.
//  Copyright © 2016年 zic_magic. All rights reserved.
//

#import "ThemeLabel.h"
#import "ThemeManager.h"

@implementation ThemeLabel

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self _observeThemeChangeNotification];
    }
    return self;
}

-(void)awakeFromNib {
    
    [super awakeFromNib];
    [self _observeThemeChangeNotification];
}

- (void)_observeThemeChangeNotification {
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeChangeAction:) name:kThemeChangeNotification object:nil];
    
}

- (void)themeChangeAction:(NSNotification *)notification {
    
    [self loadColor];
    
}

- (void)setColorName:(NSString *)colorName {
    
    if (_colorName != colorName) {
        _colorName  = [colorName copy];
        
        [self loadColor];
    }
}


- (void)loadColor {
    
    ThemeManager *manager = [ThemeManager shareManager];
    
    
    self.textColor = [manager themeColorWithColorName:_colorName];
    
    
}

- (void)dealloc {
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kThemeChangeNotification object:nil];
}

@end
